package com.ganmiao.resp;

/**
 * @Author zero.yin
 * @Date 2022/7/22 3:22 PM
 * @Desc
 */
public enum ResponseCode {
    FAIL(-1, "处理失败"),
    SUCCESS(100, "处理成功"),
    SERVER_EXCEPTION(900, "网络异常，请您稍后访问或者联系管理员！"),
    JWT_EXCEPTION(999, "JWT令牌错误"),
    USER_STATUS(0, "账户已停用"),

    //业务响应码
    TOKEN_EXPIRED_EXCEPTION(999, "登录信息已过期或者帐号已被重新登录，请您重新登录！"),
    BUSINESS_EXCEPTION(901, "业务异常"),//默认异常码
    PAY_ON_GOING(902, "支付交易进行中"),
    ;

    private Integer code;

    private String desc;

    public void setDesc(String desc) {
        this.desc = desc;
    }

    /**
     * @param code 响应码
     * @param desc 响应描述
     */
    private ResponseCode(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static ResponseCode getByCode(Integer code) {
        ResponseCode s = FAIL;
        for (ResponseCode e : ResponseCode.values()) {
            if (e.code.equals(code)) {
                s = e;
                break;
            }
        }
        return s;
    }
}
